package fr.upmc.cie.ext;

import java.util.ArrayList;

import fr.upmc.cie.R;
import fr.upmc.cie.data.TicketItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TicketListAdapter extends BaseAdapter{

	 private ArrayList<TicketItem> items;
	 
	 private LayoutInflater mInflater; 
	 
	 public TicketListAdapter(Context context, ArrayList<TicketItem> items){
		 this.items = items;
		 mInflater = LayoutInflater.from(context);
	 }
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TicketItemViewHolder holder;
		if (convertView == null) {
		   convertView = mInflater.inflate(R.layout.ticket_item, null);
		   holder = new TicketItemViewHolder();
		   holder.txtTitle = (TextView) convertView.findViewById(R.id.ticketTitle);
		   holder.txtSource = (TextView) convertView.findViewById(R.id.ticketSourceAndDate);
		   
		   convertView.setTag(holder);
		} else {
			holder = (TicketItemViewHolder) convertView.getTag();
		}
		
		holder.txtSource.setText(items.get(position).getSource());
		holder.txtTitle.setText(items.get(position).getTitle());

		return convertView;
	}

}
